home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 3.3 KB | 113 lines | [TEXT/ttxt] |
- --<<<
- -- Filename:
- -- grphmenu.sx
-
- -- Other Files Required:
- -- none
-
- -- Purpose:
- -- Create a GrapherMenu class.
-
- -- Specialized Classes:
- -- GrapherMenu
-
- -- Instructions to User:
- -- GrapherMenu is a centered menu with a graphic background, meant to
- -- hold a list of graphable properties which can be added to dynamically.
-
- -- Author:
- -- Dionn Stewart, Steve Gano, Steve Mayer, Ray Davis
-
- in module Autofinder
-
- class GrapherMenu (Menu)
- instance variables
- hmarg -- left margin for menu items
- vmarg -- top margin for menu items
- itemWidth -- width of menu items
- itemHeight -- height of menu items
- fontChanges -- keyed linked list of text attributes to change
- end
-
- method init self {class GrapherMenu} #rest args #key \
- hmarg:(20) vmarg:(20) \
- itemWidth:(undefined) itemHeight:(25) \
- fontChanges:(new KeyedLinkedList) \
- background:(undefined) boundary:(undefined) ->
- (
- apply nextMethod self placement:@menuRight args
- self.hmarg := hmarg
- self.vmarg := vmarg
- self.itemWidth := itemWidth
- self.itemHeight := itemHeight
- self.fontChanges := fontChanges
- self
- )
-
- method afterinit self {class GrapherMenu} #rest args #key \
- background: (undefined) boundary: (undefined) ->
- (
- apply nextMethod self args
- self.layoutController.wholespace:= false
- if background <> undefined do
- (
- background.z := -1 -- That's why we call it a background
- append self background
- if boundary = undefined do
- boundary := background.boundary
- )
- self.targetPresenter.boundary := boundary
- if self.itemWidth = undefined do
- self.itemWidth := self.targetPresenter.width - (self.hmarg * 2)
- self
- )
-
- -- override the place method to keep the menu in the center of the graph
- method place self {class GrapherMenu} theEvent ->
- (
- nextMethod self theEvent
- -- If we counted correctly, the next line should reach our Grapher
- local stage := self.invoker.presentedBy.presentedBy.presentedBy
- self.x:= (stage.width - self.width)/2
- self.y:= (stage.height - self.height)/2
- self
- )
-
- method addPropertyToMenu self {class GrapherMenu} prop ->
- (
- local pb := makePropertyButton self prop.axisTarget
- -- when button is activated call changeproperty on the axis that invoked
- -- the menu with this property
- pb.activateAction := (adata button -> changeProperty adata.invoker.presentedBy prop)
- pb.authordata := self
- -- add the pushbutton to the menu
- append self pb
- if (append self.layoutController pb) = 1 do
- -- Set the top margin
- self.layoutController[1].y := self.vmarg
- )
-
- -- Subclasses or instances can override this to set the attributes
- -- of the textpresenters of the buttons, or change the buttons
- -- to some other type of presenter
-
- method makePropertyButton self {class GrapherMenu} target ->
- (
- local pb := new pushbutton \
- pressedPresenter:\
- (new textPresenter boundary:(new rect x2:self.itemWidth y2:self.itemHeight) \
- fill:undefined stroke:blackbrush target:target) \
- releasedPresenter:\
- (new textPresenter boundary:(new rect x2:self.itemWidth y2:self.itemHeight) \
- fill:undefined stroke:undefined target:target)
- setDefaultAttr pb.releasedPresenter @brush whitebrush
- forEachBinding self.fontChanges (key val arg ->
- setDefaultAttr pb.pressedPresenter key val
- setDefaultAttr pb.releasedPresenter key val
- ) undefined
- pb.x := self.hmarg
- pb
- )
- "Compiled grphmenu.sx"
- -->>>
-